<?php

namespace App\Trip\Orders\BookOrders\Params\Plane;

use App\Models\Plane\PlaneOrders\PlaneOrder;
use App\Trip\Orders\BookOrders\Params\AbstractOrderParam\AbstractOrderParam;
use Exception;
use Illuminate\Support\Facades\Validator;
use InvalidArgumentException;

class ChangePlaneOrderParam extends AbstractOrderParam
{
    public array       $order_data;
    private PlaneOrder $origin_order_info;

    public function __construct(array $param, PlaneOrder $origin_order_info)
    {
        $this->order_data        = $param;
        $this->origin_order_info = $origin_order_info;
    }

    public function getOrder(): array
    {
        $validator = Validator::make($this->order_data, [
            'change_key' => 'required',
        ]);
        if ($validator->fails()) {
            throw new InvalidArgumentException($validator->errors()->first());
        }
        return $this->order_data;
    }

    public function OrderService(): string
    {
        return $this->origin_order_info->getOrderService();
    }

    /**
     * 改签暂时不支持选座
     *
     * @return array
     * @throws Exception
     */
    public function getSelectSeat(): array
    {
        return [];
    }

    /**
     * @throws Exception
     */
    public function getTripId(): string
    {
        return $this->origin_order_info->getTripId();
    }


    public function isSnapUp(): bool
    {
        return false;
    }

    /**
     * 获取外部单号
     *
     * @return string
     */
    public function getOutOrderSn(): string
    {
        return $this->order_sn;
    }
}